package com.aplana.ccsd.util;

import info.magnolia.module.blossom.dialog.DialogCreationContext;
import info.magnolia.module.blossom.dialog.RuntimeRepositoryException;
import info.magnolia.module.blossom.dialog.TabBuilder;
import info.magnolia.module.categorization.controls.CategorizationUUIDMultiSelect;
import info.magnolia.module.data.controls.DataUUIDMultiSelect;
import info.magnolia.module.templatingkit.dam.dialog.DialogDAM;
import info.magnolia.objectfactory.Classes;

import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;

public class DialogUtils {

	public static void addDamControl(TabBuilder tab, String name, String label,
			String description) {
		try {
			DialogDAM control = Classes.getClassFactory().newInstance(
					DialogDAM.class);
			control.setName(name);
			control.setLabel(label);
			control.setDescription(description);
			DialogCreationContext context = tab.getContext();
			control.init(context.getRequest(), context.getResponse(),
					context.getWebsiteNode(), null);
			control.setConfig("i18nBasename",
					"info.magnolia.module.templatingkit.messages");
			tab.getTab().addSub(control);
			control.setConfig("type", PropertyType.STRING);
		} catch (RepositoryException e) {
			throw new RuntimeRepositoryException(e);
		}
	}

	public static void addDataUUIDMultiSelectControl(TabBuilder tab, String name,
			String label, String description, String tree) {
		
		
		//DataUUIDMultiSelect control = (DataUUIDMultiSelect) tab.addControl(
				//"dataUUIDMultiSelect", name, label, description);
		//control.setRequired(true);
		//control.setConfig("tree", "data");
		//control.setConfig("repository", "data");
		// control.setConfig("type", PropertyType.STRING);
		
		//info.magnolia.module.categorization.controls.CategorizationUUIDMultiSelect c;
		info.magnolia.module.categorization.controls.CategorizationSaveHandler sh;
		
		//DialogU
		try {
			// sh;
			//DataUUIDMultiSelect d;
			CategorizationUUIDMultiSelect control = Classes.getClassFactory().newInstance(
					CategorizationUUIDMultiSelect.class);
			//DataUUIDMultiSelect control = Classes.getClassFactory().newInstance(
					//DataUUIDMultiSelect.class);
			//DataUUIDMultiSelect control = (DataUUIDMultiSelect) tab.addControl(
					//"dataUUIDMultiSelect", name, label, description);
			//com.aplana.ccsd.web.control.TechnologySaveHandler;
			control.setName(name);
			control.setLabel(label);
			control.setDescription(description);
			
			
			DialogCreationContext context = tab.getContext();
			control.init(context.getRequest(), context.getResponse(),
					context.getWebsiteNode(), null);
			control.setConfig("tree", tree);
			control.setConfig("saveHandler", "com.aplana.ccsd.web.control.TechnologySaveHandler");
			control.setConfig("type", PropertyType.STRING);
			control.setConfig("repository", "data");
			control.setConfig("i18nBasename",
					"info.magnolia.module.categorization.messages");
			tab.getTab().addSub(control);
			
		} catch (RepositoryException e) {
			throw new RuntimeRepositoryException(e);
		}
	}
}
